﻿function newElement(str) {
	return document.createElement(str);
}

// new表格
function Table(tableStructure, tableName, formName) {
	this.isShowBlankTr = false; //是否显示空白行
	this.defaultWidth = 120;// 默认的列宽
	this.pageSize = 10;// 每页显示的记录
	this.pageIndex = 1;// 当前页的索引
	this.totalRows = 0;// 总记录行数
	this.pageCount = 0;// 共有多少页（总页数）
	this.pageRows = 0;// 当前页记录个数
	this.url = "";// 数据url
	this.selectType = "generic";// 选择类型
	this.tableStructure = tableStructure;// 所有对象
	this.tableDiv = null;// 生成的脚本存方的位置
	this.tableName = tableName;// 生成的对像名称。必须传进来
	this.tableId= this.tableName+ "Table";
	this.formName = formName;// 看是否有form表单操作如果有的话，则增加查询条件
	this.selectRowIndexes = [];// 选中行的索引数组
	this.trHeight = 20;// 行高，默认20
	this.rowClick = null;// 点击事件
	this.rowDbClick = null;// 双击事件
	this.titleSpan = null;// 合并表头信息
	this.isFooter = true;// 是否显示分页信息
	this.isShowCheck=true;//是否显示radio/checkbox控件
	this.opCode = "";// 操作的对像(如增加，详细页面的文件名)，用于龙虎说的增删改查的全部封装()
	this.opName = "";// 同上，表示增删改查的titfle名
	this.orderName = "";
	this.orderType = "";
	this.defaultSelectedRowIndex = 0;
	this.datas = [];// 初始化表格数据信
	this.columns = [];// 初始化表格列信息
	this.titleTr = "";// 表头字符串
	this.content = "";// 内容字符串
	this.footer = "";// 脚本字符串
	this.tableConfigDiv = null;// 表格配置div
	this.tableWidth = 0;
	this.closeMethod = null;
	this.buttonDatas = [];// 默认按钮
	this.cookieColumns = [];
	this.columnsColors = [ "#ff0000", "#00FFff", "#0000ff", ];
	this.extendAttribute=null;
	this.trOverColor = '#D7DAD1';// 鼠标经过颜色
	this.trSelectedColor = '#FD9632';
	this.lockRows=[];
	this.checkedForm=false;
	this.trOnmouseover='';
	this.trMoveDiv = null;
	this.tdButtonEvents=[];
	this.moveObj = new function() {
		this.opTd = null;
		this.startX = 0;
		this.endX = 0;
		this.status = false;
		this.mouseMove = null;
		this.mouseUp = null;
		this.selectstart = null;
	};
	
	this.openWinStyle = "dialogWidth=" + (window.screen.availWidth )
			+ "px;dialogHeight=" + (window.screen.availHeight) + "px; status=no; scroll=no; resizable=no;";// 用于简单的增删改查操作
	// ---
	if (this.tableStructure) {
		if (this.tableStructure.isShowBlankTr != undefined
				&& (this.tableStructure.isShowBlankTr == "false" 
				|| this.tableStructure.isShowBlankTr == false)) {
			this.isShowBlankTr = false;
		}
		if (this.tableStructure.isFooter
				&& this.tableStructure.isFooter == "false") {
			this.isFooter = false;
		}
		if (this.tableStructure.pageSize) {
			this.pageSize = this.tableStructure.pageSize;
		}
		if (this.tableStructure.url) {
			this.url = this.tableStructure.url;
		}
		if (this.tableStructure.selectType) {
			this.selectType = this.tableStructure.selectType;
		}
		if (this.tableStructure.rownumbers) {
			this.rownumbers = this.tableStructure.rownumbers;
		}

		if (this.tableStructure.trHeight) {
			this.trHeight = this.tableStructure.trHeight;
		}
		if (typeof (this.tableStructure.rowClick) == "function"){
			this.rowClick = this.tableStructure.rowClick;
		}else if(typeof (this.tableStructure.rowClick) == "string"){
			this.rowClick = eval(this.tableStructure.rowClick.replace("(","").replace(")", ""));
		}
		if (typeof (this.tableStructure.rowDbClick) == "function") {
			this.rowDbClick = this.tableStructure.rowDbClick;
		} else if (typeof (this.tableStructure.rowDbClick) == "string") {
			this.rowDbClick = eval(this.tableStructure.rowDbClick.replace("(","").replace(")", ""));
		}
		
		if (typeof (this.tableStructure.rowMouseOver) == "function") {
			this.rowMouseOver = this.tableStructure.rowMouseOver;
		} else if (typeof (this.tableStructure.rowMouseOver) == "string") {
			this.rowMouseOver = eval(this.tableStructure.rowMouseOver.replace("(","").replace(")", ""));
		}
		if (typeof (this.tableStructure.rowMouseOut) == "function") {
			this.rowMouseOut = this.tableStructure.rowMouseOut;
		} else if (typeof (this.tableStructure.rowMouseOut) == "string") {
			this.rowMouseOut = eval(this.tableStructure.rowMouseOut.replace("(","").replace(")", ""));
		}
		
		if (this.tableStructure.titleSpan) {
			this.titleSpan = this.tableStructure.titleSpan;
		}
		if (this.tableStructure.opCode) {
			this.opCode = this.tableStructure.opCode;
		}
		if (this.tableStructure.opName) {
			this.opName = this.tableStructure.opName;
		}
		if(this.tableStructure.extendAttribute){
			this.extendAttribute=this.tableStructure.extendAttribute;
		}
		if (this.tableStructure.buttons) {
			this.buttonDatas = this.tableStructure.buttons;
		}
		if (this.tableStructure.useDefaultButtons) {
			this.buttonDatas = defaultTableButtons.datas;
		}
		if(this.tableStructure.checkedForm){
			this.checkedForm=true;
		}
		if(this.tableStructure.isShowCheck&&this.tableStructure.isShowCheck=="false"){//设置是否显示checkbox radio列
			this.isShowCheck=false;
		}
		if (this.tableStructure.lockRows) {
			this.lockRows = this.tableStructure.lockRows;
		}
		
		if(this.tableStructure.columnShadow){//字段列做投影操作，如果查询出的字段名称与实际名称不符合可以用此集合来做映射，而不需要修改后台代码
			this.columnShadow=this.tableStructure.columnShadow;
		}
		
		if (this.tableStructure.columns) {
			for ( var i = 0; i < this.tableStructure.columns.length; i++) {
				var column = this.tableStructure.columns[i];
				if (!(column.hidden && column.hidden == "true")) {
					this.columns.push(column);
				}
			}
		}
		if (this.tableStructure.data) {
 
			if (this.tableStructure.data.rows) {
				this.datas = this.tableStructure.data.rows;
			}
			if (this.tableStructure.data.pageIndex) {
				this.pageIndex = this.tableStructure.data.pageIndex;
			}
			if (this.tableStructure.data.totalRows) {
				this.totalRows = this.tableStructure.data.totalRows;
			}
			if (this.datas) {
				this.pageRows = this.datas.length;
			}
		}
		if (this.columns) {
			var cookieStr = JBF.getCookieByName();
			if (cookieStr) {
				var cookies = JBF.strToObj(cookieStr);
				var cookieColumns = cookies["columns"];
				var cookieColors = cookies["colors"];
				if (cookieColumns) {
					for ( var i = 0; i < cookieColumns.length; i++) {
						for ( var j = 0; j < this.columns.length; j++) {
							if (cookieColumns[i]["name"] == this.columns[j].name) {
								var width = cookieColumns[i]["width"];
								this.columns[j].width = Number(width);
								this.cookieColumns.push(this.columns[j]);
							}
						}
					}
				}
				if (cookieColors) {
					if (cookieColors["overColor"]) {
						this.trOverColor = cookieColors["overColor"];
					}
					if (cookieColors["selectedColor"]) {
						this.trSelectedColor = cookieColors["selectedColor"];
					}
				}
			} else {
				this.cookieColumns = this.columns;
			}
		}
	}
}
Table.prototype = {
	mousePresss : function(columnIndex, ev, cty) {
		if (null != this.trMoveDiv) {
			this.trMoveDiv.style.display = "inline";
		} else {
			var absY = JBF.getAbsY(cty);
			var table = JBF.getParentNodeByNodeName("TABLE", cty);
			var absHeight = "100px";
			if (null != table) {
				absHeight = JBF.getObjHeight(table);
			}
			this.trMoveDiv = document.createElement("div");
			this.trMoveDiv.className = "trMoveDiv";
			this.trMoveDiv.style.top = absY + "px";
			this.trMoveDiv.style.height = absHeight + "px";
			document.body.appendChild(this.trMoveDiv);
		}
		var x = JBF.getX(ev) + 2;
		this.trMoveDiv.style.left = x + "px";
		this.moveObj.startX = x;
		this.moveObj.endX = x;
		this.moveObj.opTd = JBF.getParentNodeByNodeName("TD", cty);
		this.moveObj.status = true;

		this.moveObj.mouseMove = this.tdMouseMove();
		this.moveObj.mouseUp = this.tdMouseUp();
		this.moveObj.selectstart = this.tableSelect();

		JBF.addEvent(document.body, "mousemove", this.moveObj.mouseMove);
		JBF.addEvent(document.body, "mouseup", this.moveObj.mouseUp);
		JBF.addEvent(document.body, "selectstart", this.moveObj.selectstart);
	},
	tdMouseMove : function() {
		var that = this;
		return function() {
			if (that.moveObj.status) {
				var x = JBF.getX(arguments.event) + 2;
				that.trMoveDiv.style.left = x + "px";
				that.moveObj.endX = x;
			}
		};
	},
	tableSelect : function() {
		return function() {
			return false;
		};
	},
	tdMouseUp : function() {
		var that = this;
		return function() {
			var offset = that.moveObj.endX - that.moveObj.startX;
			var tdWidth = JBF.getObjWidth(that.moveObj.opTd) + offset;
			that.moveObj.opTd.style.width = tdWidth + "px";
			// alert(that.moveObj.opTd.attributes["columnName"].value);
			JBF.removeEvent(document.body, "mousemove", that.moveObj.mouseMove);
			JBF.removeEvent(document.body, "mouseup", that.moveObj.mouseUp);
			JBF.removeEvent(document.body, "selectstart",
					that.moveObj.selectstart);
			that.moveObj.status = false;
			var tableWidth = JBF.el(that.tableId).style.width
					.replace("px", "");
			JBF.el(that.tableId).style.width = (Number(tableWidth) + offset)
					+ "px";
			that.trMoveDiv.style.display = "none";
			that.changeColumnWidth(
					that.moveObj.opTd.attributes["columnName"].value, tdWidth);
		};
	},
	changeColumnWidth : function(name, width) {
		for ( var i = 0; i < this.columns.length; i++) {
			if (this.columns[i].name == name) {
				this.columns[i].width = width;
			}
		}
	},
	/**
	 * 行鼠标经过移出事件
	 */
	outTrClass : function(trObj, rowIndex) {
		if (trObj.className != 'trOnClick') {
			if (trObj.attributes["srcClass"]) {
				trObj.className = trObj.attributes["srcClass"].value;
			} else {
				trObj.className = '';
			}
			trObj.style.backgroundColor = '';
		}
	},
	/**
	 * 行鼠标单击事件，如果单击时行背景色变化。同时如果checkbox类型，则将选中的行索引加入到keyIndexs
	 * 如果传递了行单击事件，还会执行，行单击事件
	 */
	clickRow : function(rowIndex) {// 行鼠标单击
		if(this.datas&&this.datas.length>0){
			if (this.selectType == "radio" || this.selectType == "generic") {
				if (this.selectRowIndexes.length == 0) {
					this.selectRow(rowIndex);
				} else {
					if (rowIndex == this.selectRowIndexes[0])
						return;
					else {
						this.deSelectRow(this.selectRowIndexes[0]);
						this.selectRow(rowIndex);
					}
				}
			} else if (this.selectType == "check") {
				if (this.isRowSelected(rowIndex)) {
					this.deSelectRow(rowIndex);
					return;
				}
				this.selectRow(rowIndex);
			}
			if(null!=this.rowClick){
				this.rowClick(rowIndex, this.datas[rowIndex].id,this.tableStructure.extendAttribute);
			}
		}
	},
	/**
	 * 行双击事件，所触发的事件
	 */
	dbClickRow : function(rowIndex) {
		if (null != this.rowDbClick) {
			this.rowDbClick(rowIndex, this.datas[rowIndex].id,this.tableStructure.extendAttribute);
		}
	},
	/**
	 * 检查当前选中行在keyIndexs数组中是否有此索引值，如果有的话，则不在存储到此数据中(只有在多选时才用到)
	 */
	isRowSelected : function(rowIndex) {
		// --用来存储选中值的索引
		for ( var i = 0; i < this.selectRowIndexes.length; i++) {
			if (this.selectRowIndexes[i] == rowIndex) {
				return true;
			}
		}
		return false;
	},
	/**
	 * -删除数组当中的值
	 */
	deSelectRow : function(rowIndex) {
		// this.datas.splice(index, 1);
		for ( var i = 0; i < this.selectRowIndexes.length; i++) {
			if (this.selectRowIndexes[i] == rowIndex) {
				this.selectRowIndexes.splice(i, 1);
				this.changeRowClassName("", rowIndex);
				// 修改颜色
				return;
			}
		}
		return;
	},

	/**
	 * 行鼠标经过移入事件
	 */
	overTrClass : function(otc) {
		if (!(otc.className && otc.className.length > 0 && otc.className == 'trOnClick')) {
			oldTrClassName = otc.className;
			otc.className = 'trOver';
			otc.style.backgroundColor = this.trOverColor;
		}
		if(this.rowMouseOver){
			this.rowMouseOver(11);
		}
	},
	/**
	 * 进行排序操作
	 */
	onclickTitle : function(columnName) {// 进行排序操作
		if (this.orderName == columnName) {
			if (this.orderType == "asc") {
				this.orderType = "desc";
			} else if (this.orderType == "desc") {
				this.orderType = "";
				this.orderName = "";
			} else {
				this.orderType = "asc";
			}
		} else {
			this.orderName = columnName;
			this.orderType = "asc";
		}
		this.searchByForm();
	},

	/**
	 * 选择所有记录（同是改变选择行的背景色，如果checkbox则选取所有，如果radio则选择当前项）
	 */
	checkedAll : function(cty) {
		var className = "checkbox_checked";
		var bit = true;
		if (cty.className && cty.className == className) {
			className = "checkbox";
			bit = false;
		}
		cty.className = className;
		for ( var i = 0; i < this.datas.length; i++) {
			// JBF.el("check"+i).className=className;
			if(!this.isLockTrByIndex(i)){
				if (bit) {
					this.selectRow(i);
				} else {
					this.deSelectRow(i);
				}
			}
		}
	},
	/**
	 * 首页
	 */
	pre_first : function() {
		this.pageIndex = 1;
		this.searchByForm();
	},
	/**
	 * 上一页
	 */
	pre_page : function() {
		this.pageIndex -= 1;
		this.searchByForm();
	},
	/**
	 * 下一页
	 */
	next_page : function() {
		this.pageIndex += 1;
		this.searchByForm();
	},
	/**
	 * 尾页
	 */
	next_end : function() {
		this.pageIndex = this.pageCount;
		this.searchByForm();
	},
	/**
	 * 刷新页面
	 */
	flush_page : function(pageIndex) {
		if (pageIndex) {
			this.pageIndex = pageIndex;
		} else {
			var flushInput=JBF.el(this.tableName + "FlushInput");
			if(flushInput&&flushInput.value){
				if (flushInput.value < this.pageCount) {
					this.pageIndex = flushInput.value;
				} else if (flushInput.value < 1) {
					this.pageIndex = 1;
				} else {
					this.pageIndex = this.pageCount;
				}
			}else{
				this.pageIndex=1;
			}
		} 
		this.searchByForm();
	},
	/**
	 * 按钮鼠标经过时
	 */
	btn_over : function(cty) {
		cty.className = cty.className + " fonterBtnDivOver";
	},
	/**
	 * 按钮鼠标离开
	 */
	btn_out : function(cty) {
		cty.className = cty.className.replace(" fonterBtnDivOver", "");
	},
	/**
	 * 获取指定字段的值，并通过数组形式返回
	 */
	getSelectedValues : function(columnName,rowIndex) {
		var key = columnName;
		if (!key) {
			key = "id";
		}
		var values = [];
		//alert("typeof(rowIndex):"+typeof(rowIndex));
		if(rowIndex!=undefined&&typeof(rowIndex)=="number"){
			var data = this.groupEditValue(this.datas[rowIndex], key, rowIndex);
			values.push(data[key]);
		}else{
			for ( var i = 0; i < this.selectRowIndexes.length; i++) {
				var dataIndex=parseInt(this.selectRowIndexes[i]);
				var data = this.groupEditValue(this.datas[dataIndex], key, dataIndex);
				values.push(data[key]);
			}
		}
		return values;
	},
	groupEditValue:function(data,columnName,rowIndex){
		var column=this.getColumnByName(columnName);
		if(column&&column.isEdit){
			var name=column.name+"EditInput_"+rowIndex;
			if(JBF.el(name)){
				data[column.name]=JBF.el(name).value;
			}
		}
		return data;
	},
	/**
	 * 根据选择行索引，获取某字段的值
	 */
	getValueForIndex : function(columnName, rowIndex) {
		var key = columnName;
		if (!key) {
			key = "id";
		}
		var rowData = this.datas[rowIndex];
		return rowData[key];
	},
	setValueForIndex : function(rowIndex, columnName, value) {
		var data = this.datas[rowIndex];
		data[columnName] = value;
		this.refreshDatas();
	},
	/**
	 * 设置行的背景
	 */
	setRowBgColor : function(rowIndex, bgColor) {
		JBF.el(this.tableId).rows[rowIndex+1].style.backgroundColor = bgColor;
	},
	/**
	 * 得到行的记录数
	 */
	getRowsCount : function() {
		return this.datas.length;
	},

	/**
	 * 显示表格的主函数,用于整合表格，并放到页面中的指定位置//有问题，需要修改
	 */
	show : function(tableDiv) {
		if (tableDiv) {
			this.tableDiv = tableDiv;
		} else {
			this.tableDiv = newElement("div");
			this.tableDiv.id = "tableDiv";
			document.body.appendChild(this.tableDiv);
		}
		this.refreshDatas();

	},
	showAndQuery : function(tableDiv) {
		if (tableDiv) {
			this.tableDiv = tableDiv;
		} else {
			this.tableDiv = newElement("div");
			this.tableDiv.id = "tableDiv";
			document.body.appendChild(this.tableDiv);
		}
		this.searchByForm();
	},
	toHtml:function(){
		var tohtml=this.searchByForm(true);
		if(this.datas&&this.datas.length>0){
			this.selectRowIndexes.push(0);
		}
		return tohtml;
	},

	/** 通过url,及查询条件进行查询操作* */
	searchByForm : function(isToHTML) {
		var that = this;
		var tableStr="";
		this.selectRowIndexes = [];
		if(this.url){
			var params=this.getParams();
			var searchBit=true;
			if(this.checkedForm&&params.length<=0){
				alert("查询条件不符合规范");
				searchBit=false;
			} 
			if(searchBit){
				var pageInfo=this.getPagesParams();
				JBF.ajax(this.url, pageInfo+params, function(msg) {
					if (msg && msg.pageList) {
						if (typeof (msg.pageSize) == "number") {
							that.pageSize = msg.pageSize;
						}
						that.datas = msg.pageList;
						that.groupColumnsShadow(that.datas);
						if (typeof (msg.totalRows) == "number") {
							that.totalRows = msg.totalRows;
						}
						if (typeof (msg.pageIndex) == "number") {
							that.pageIndex = msg.pageIndex;
						}
						// 刷新表格
						tableStr=that.refreshDatas(isToHTML);
					}
				});
			}
		}else{
			tableStr=this.refreshDatas(isToHTML);
		}
		if(isToHTML){
			return tableStr;
		}
	},
	groupColumnsShadow:function(datas){
		if(datas&&datas.length>0&&this.columnShadow&&this.columnShadow.length>0){
			for(var i=0;i<datas.length;i++){
				this.groupColumnShadow(datas[i]);
			}
		}
	},
	groupColumnShadow:function(data){
		if(this.columnShadow&&this.columnShadow.length>0){
			for(var j=0;j<this.columnShadow.length;j++){
				var shadow=this.columnShadow[j];
				if(shadow.length>1){
					var newData=data;
					newData[shadow[0]]=newData[shadow[1]];
					data=newData;
				}
			}
		}
		return data;
	},
	getPagesParams:function(){
		if (JBF.el(this.tableName + "pageSize")) {
			this.pageSize = JBF.el(this.tableName + "pageSize").value;
		}
		var params = "pageIndex=" + this.pageIndex + "&pageSize="
				+ this.pageSize + "&selectRowIndex=" + this.selectRowIndexes;
		if (this.orderName && this.orderType) {
			params += "&orderName=" + this.orderName + "&orderType="
					+ this.orderType;
		}
		return params;
	},
	getParams : function() {
		var params="";
		if (this.formName) {
			var formStr="";
			if(this.checkedForm){
				formStr = ( eval(this.formName + ".checkPojos()"));
				if(formStr.length<1){
					return "";
				}
			}else{
				formStr = ( eval(this.formName + ".getValues()"));
			}
			params+="&"+formStr;
		}
		return params;
	},

	/**
	 * 整合表格，将表头，内容，及表尾进行整合
	 */
	refreshDatas : function(isToHTML) {
		this.tableWidth = 0;
		this.createTableTitle();
		this.createTableFoot();
		this.tableContentTr();
		if(this.isShowBlankTr){
			this.createBlankTr();
		}
		var str = "<div class='tableDiv' id='" + this.tableName
				+ "TableDiv' name='" + this.tableName + "TableDiv' "
				+ "style=' height:" + "px;' " + "><table  id='"
				+ this.tableName
				+ "Table' cellpadding='0' cellspacing='0' style='width:"
				+ this.tableWidth + "px;'>";
		str += this.titleTr;
		str += this.content;
		str += "</table></div>";
		if (this.footer && this.isFooter) {
			str += "<div class='footerDiv' id='footerDiv' name='footerDiv'>"
					+ this.footer + "</div>";
		}
		if(isToHTML){
			return str;
		}
		this.tableDiv.innerHTML = str;
		if ((this.selectType == 'radio' || this.selectType == 'generic')
				&& this.selectRowIndexes.length == 0) {
			if (this.datas.length > 0)
				this.clickRow(0);
		} else {
			if (this.selectType == 'radio' || this.selectType == 'generic') {
				var curRowIndex = this.selectRowIndexes[0];
				this.selectRowIndexes.length = [];
				this.clickRow(curRowIndex);
			}
		}
		// 用来做ie7-ie8中的处理滚动条的部分
		if (JBF.getBrowseIsIe()) {
			if (JBF.getBrowseVersion() < 8) {
				var tableWidth = JBF.getObjWidth(JBF.el(this.tableId));
				var div = JBF.el(this.tableName + "TableDiv");
				var divWidth = JBF.getObjWidth(div);
				var divHeight = JBF.getObjHeight(div);
				if (tableWidth > divWidth) {
					div.style.height = (divHeight + 16) + "px";
				}
			}
		}
	},
	/**
	 * 删除选择的记录（全部交给框架来完成，直接通过url来删除）
	 */
	delPojo : function(url) {
		var ids = this.getSelectedValues('id');
		if (ids.length <= 0) {
			alert("请选择数据后，再点击操作按钮。");
			return;
		}
		if (confirm("请确认要删除选中行的数据吗？")) {
			var table = this;
			JBF.ajax(url, "id=" + ids.toString(), function() {
				table.removeSelectedTR();
			});
		}
	},
	/**
	 * 开放接口，用于直接移除选中的行
	 */
	removeSelectedTR : function() {
		var isLastRow = (this.selectType == "radio" || this.selectType == 'generic')
				&& this.selectRowIndexes[0] == (this.datas.length - 1);
		var ids = this.getSelectedValues('id');
		if(ids&&ids.length>0){
			var datas = this.datas;
			var newDatas = [];
			for ( var i = 0; i < datas.length; i++) {
				var data = datas[i];
				var bit = true;
				for ( var j = 0; j < ids.length; j++) {// 过滤选择的数据。
					if (data.id == ids[j]) {
						bit = false;
						j = ids.length;
					}
				}
				if (bit) {// 没有选择的数据进行重新整合，
					newDatas.push(datas[i]);
				}
			}
			this.datas = newDatas;// 对整合后的数据进行重绘按钮
			var curSelectRow = this.selectRowIndexes[0];
			this.selectRowIndexes.length = 0;
			if ((this.selectType == "radio" || this.selectType == 'generic')
					&& isLastRow) {
				if (this.datas.length > 0)
					this.selectRowIndexes.push(curSelectRow - 1);
			} else if (this.selectType == "radio" || this.selectType == 'generic') {
				this.selectRowIndexes.push(curSelectRow);
			}
			this.refreshDatas();
		}
	
//		alert("表中数据已经为空不能进行移除操作，请刷新后再点击删");
	},
	/**
	 * 增加一条新的记录//
	 */
	addPojo : function(params) {
		if (!this.datas) {
			var rows = new Array();
			this.datas = rows;
		}
		this.groupColumnShadow(params);
		this.datas.unshift(params);
		this.selectRowIndexes.length = 0;
		this.selectRowIndexes.push(0);
		this.refreshDatas();
	},
	/**
	 * 修改数据当中的一条记录(然后进行全部刷新表格，使其重新展示);
	 */
	modifyPojo : function(params) {
		var id = this.getSelectedValues('id');
		for ( var i = 0; i < this.datas.length; i++) {
			if (id == this.datas[i].id) {
				this.datas[i] =this.groupColumnShadow(params);
				i = this.datas.length;
			}
		}
		this.refreshDatas();
	},
	/**
	 * 修改表格数据刷新一行数据，主要体现是的居部刷新
	 */
	flushTableTr:function(trObj,rowIndex){
		var table=JBF.el(this.tableId);
		var trRow=table.rows[rowIndex+1];
		var tds=trRow.cells;
		if(tds){
			for(var i=0;i<tds.length;i++){
				var td=tds[i];
				var tdType=td.attributes["tdType"];
				var isEdit=td.attributes["isEdit"];
				if(isEdit&&isEdit.value){
					td.setAttribute("isEdit","");
				}
				if(tdType&&tdType.value&&tdType.value=="text"){
					var tdNode=td.attributes["cName"];
					if(tdNode&&tdNode.value){
						var column=this.getColumnByName(tdNode.value);
						if(column){
							value=this.createTdInnerHTML(column, trObj[tdNode.value]);
							td.innerHTML=value;
						}
					}
				}
			}
			this.datas[rowIndex]=trObj;
		}
		this.selectRow(rowIndex);
	},
	/**
	 * 通过字段名来获取到字段名称
	 */
	getColumnByName:function(columnName){
		for(var i=0;i<this.cookieColumns.length;i++){
			var column=this.cookieColumns[i];
			if(column.name==columnName){
				return column;
			}
		}
		return null;
	},
	/**
	 * 整合表头数据
	 */
	createTableTitle : function() {// 整合表头
		var columns = this.cookieColumns;// this.columns;
		var trStr = "<tr class='tableHeader' id='tableHeader' width='100%' >";
		var spanStr = "";
		if (this.titleSpan) {// 用于合并表格操作
			spanStr += " rowspan='2' class='tableSpanHr' ";
		}
		if (this.rownumbers) {
			this.tableWidth = 20;
			trStr += "<td nowrap "
					+ spanStr
					+ " style='width:20px; vertical-align:middle;' ><a href='javascript:void(0)' title='点击后可进行表格的配置信息操作' onclick='"
					+ this.tableName
					+ ".showTableConfig(event)' class='tableConfigIcon'></a></td>";
		}
		if(this.isShowCheck){//是否显示radio/checkbox列
			if (this.selectType) {
				if (this.selectType == "check") {
					trStr += "<td nowrap "
							+ spanStr
							+ " style='width:30px; vertical-align:middle;' ><ul><li class='tableHR'><span><div class='checkbox' id='checkAll"
							+ this.tableName + "' onclick='" + this.tableName
							+ ".checkedAll(this)'></div></span></li></ul></td>";
				} else if (this.selectType == "radio") {
					trStr += "<td nowrap "
							+ spanStr
							+ "style='width:30px; vertical-align:middle;' ><ul><li class='tableHR'><span>选择</span></li></ul></td>";
				}
				this.tableWidth += 30;
			}
		}
		if (this.titleSpan) {// 用于表格合并操作
			trStr += this.getSpanTdStr(columns, titleSpan);
		} else {
			trStr += this.getBasicTdStr(columns);
		}
		this.titleTr = trStr;
	},

	/**
	 * 得到合并单元格的字符串(优化，优化优化，优化优化，优化优化，优化)
	 */
	getSpanTdStr : function(columns, titleSpans) {
		var spanTds = new Array();// 存放第一行数据，未补合并的，及合并后的td
		var spans = new Array();// 用于存放合并后的的td在每二行显示
		for ( var i = 0; i < this.titleSpan.length; i++) {
			var title = this.titleSpan[i];// 得到合并的组合,把所有组合全部提取
			if (title.span) {
				var tdStr = "<td align='center' valign='middle' colspan='"
						+ title.span.length + "'>" + title.display + "</td>";
				spanTds.push({
					index : title.span[0],
					str : tdStr
				});
				for ( var j = 0; j < title.span.length; j++) {
					spans.push(title.span[j]);
				}
			}
		}
		// 过滤不合并的表头，因为不合并的表头，与合并的表头在同一行显示
		for ( var i = 0; i < columns.length; i++) {
			if (this.filterTdHeader(spans, i)) {
				spanTds.push({
					index : i,
					str : this.tableTitleTd(columns[i], i, true)
				});
			}
		}
		spanTds.sort(this.compare);// 根据表头第一行对表头进行排序。
		var str = "";
		for ( var i = 0; i < spanTds.length; i++) {// 整合第一行数据
			str += spanTds[i].str;
		}
		str += "</tr> <tr class='tableHeader'>";
		for ( var i = 0; i < spans.length; i++) {
			str += this.tableTitleTd(columns[spans[i]], spans[i]);
		}
		return str += "</tr>";
	},
	/*
	 * 过滤头信息(在合并单元格的前提下重新整合表头)
	 */
	filterTdHeader : function(filters, index) {
		if (filters) {
			for ( var i = 0; i < filters.length; i++) {
				if (filters[i] == index) {
					return false; // 存在合并放在第二行
				}
			}
		}
		return true;// 否则放在每一行
	},
	compare : function(td1, td2) {
		if (td1.index > td2.index) {
			return 1;
		} else if (td1.index < td2.index) {
			return -1;
		} else {
			return 0;
		}
	},
	/**
	 * 得基本形式的表格字符串
	 */
	getBasicTdStr : function(columns, rowSpan) {
		var trStr = "";
		if (columns && columns.length > 0) {
			for ( var i = 0; i < columns.length; i++) {
				trStr += (this.tableTitleTd(columns[i], i));
			}
			var spanStr = "";
			if (rowSpan) {
				spanStr += " rowspan='2' class='tableSpanHr' ";
			}
			// trStr+="<td "+ spanStr+"valign=middle style='width:0px;
			// vertical-align:middle;'></td></tr>";
			trStr += "</tr>";
		}
		return trStr;
	},
	/**
	 * 整合表头的每个字段
	 */
	tableTitleTd : function(tdObj, rowIndex, rowSpan) {
		if (typeof (tdObj) != "object") {
			return '';
		}
		var orderStr = "<li class='tableHR'><span>" + tdObj.display
				+ "</span></li>";
		if (tdObj.isOrder && (tdObj.isOrder == true||tdObj.isOrder=="true")) {
			var isOrder = this.orderName == tdObj.name;

			var orderSpan = "class='thOrderNoDes'";
			if (isOrder) {
				if (this.orderType == "desc") {
					orderSpan = "class='thOrderDesc'";
				} else if (this.orderType = "asc") {
					orderSpan = "class='thOrderAsc'";
				}

			}
			orderStr = "<li onclick='" + this.tableName + ".onclickTitle(\""
					+ tdObj.name
					+ "\",this)'  class='tableHR'><span><a href='javascript:void(0)'>"
					+ tdObj.display + "</a></span><span " + orderSpan
					+ ">&nbsp;&nbsp;&nbsp;</span></li>";
		}
		var tdStr = "";
		var widthStr = this.defaultWidth;
		if (tdObj.width) {
			widthStr = tdObj.width;
		}
		this.tableWidth += widthStr;
		widthStr += "px;";
		if (this.rownumbers) {
			++rowIndex;
		}
		if (this.selectType) {
			++rowIndex;
		}
		var spanStr = "";
		if (rowSpan) {
			spanStr += " rowspan='2' class='tableSpanHr' ";
		}
		tdStr += "<td columnName=" + tdObj["name"] + " nowrap" + spanStr
				+ " style='width:" + widthStr + ";' ><ul>" + orderStr
				+ "<li class='tabelHRMove' title='左右拖动可改变大小' onmousedown='"
				+ this.tableName + ".mousePresss(" + rowIndex
				+ ",event,this);'></li></ul></td>";
		return tdStr;
	},
	isLockTrByIndex:function(rowIndex){
		if(this.lockRows&&this.lockRows.length>0){
			for(var i=0;i<this.lockRows.length;i++){
				if(this.lockRows[i]==rowIndex){
					return true;
				}
			}
		}
		return false;
	},
	/**
	 * 整合行数据内容
	 */
	tableContentTr : function() {// 整合内容行
		var trStr = "";
		if (this.datas.length > 0) {
			for ( var d = 0; d < this.datas.length; d++) {
				var className = "";
				var srcClassName = "";
				if (d % 2 != 0) {
					className = "class='trEven' ";
					srcClassName = "srcClass='trEven' ";
				}
				var data = this.datas[d];
				if(this.isLockTrByIndex(d)){
					trStr += "<tr " + srcClassName + className + " style='height:"
					+ this.trHeight + "px;'>";
				}else{
					trStr += "<tr " + srcClassName + className + " style='height:"
					+ this.trHeight + "px;'  onmouseover='"
					+ this.tableName + ".overTrClass(this);' onmouseout='"
					+ this.tableName + ".outTrClass(this," + d
					+ ");' onclick='" + this.tableName + ".clickRow(" + d
					+ ");' ondblclick='" + this.tableName + ".dbClickRow("
					+ d + ")'>";
				}
				if (this.rownumbers) {// 是否显示行号
					var pageStartIndex = (this.pageIndex - 1) * this.pageSize;
					trStr += "<td  class='sequenceNum'>"
							+ (d + pageStartIndex + 1) + "</td>";
				}
				if(this.isShowCheck){
					if (this.selectType) {// 是否显示选择类型，check/radio
						if (this.selectType == "check") {
							trStr += "<td style='text-align:center'><div value='"
									+ d
									+ "' id='check"
									+ d
									+ "' name='checks' class='checkbox'></div></td>";
						} else if (this.selectType == "radio") {
							trStr += "<td style='text-align:center'><input value='"
									+ d + "' type='radio' id='radio" + d
									+ "' name='radios'/></td>";
						}
					}
				}
				trStr += this.tableContentTds(data,d);
				trStr += "</tr>";
			}
		} else {
			this.defaultSelectedRowIndex = -1;
		}
		//alert(trStr);
		this.content = trStr;
	},
	/**
	 * 整合内容，对每个字段进行组合
	 */
	tableContentTds : function(data,rowIndex) {// 整合内容字段
		var tdStr = "";
		if (this.cookieColumns.length > 0) {//cookieColumns实际上是通过cookie过滤的字段集合，如果没有cookie设置，则保存的原始数
			for ( var i = 0; i < this.cookieColumns.length; i++) {//通过
				var column = this.cookieColumns[i];
				var styleStr=" text-align:" + JBF.setObjValue(column.align,column.align,"left") + "; ";
				var value = "";
				var srcValue="";
				var className="";
				var tdExtAttribute=" cName='"+column.name+"'";//将字段名称记录在当前td中的某个字段中。
				if(column.type&&column.type=="button"){
					value=this.createTdButtonHTML(data,column,rowIndex);
					tdExtAttribute+=" tdType='button'";
				}else{
					if (column.name) {					
						value = data[column.name] + "";
						srcValue=value;
						value=this.createTdInnerHTML(column, value);
					}
					tdExtAttribute+=" tdType='text'";
				}
				if(column.dynamicCss){
					styleStr+=column.dynamicCss(srcValue);
				}
				if(column.dynamicClassName){
					className= " class= "+column.dynamicClassName(srcValue);
				}
				tdStr += "<td "+this.createEditEvent(column,rowIndex)+tdExtAttribute+className+" nowrap title='"+srcValue+"' valign='middle'"
						+ this.createTdExtra(column)
						+ "style='"+styleStr+"'>" + value+ "</td>";

			}
		}
		return tdStr;
	},
	
	createBlankTr:function(){
		var trHeight=(Number(this.trHeight))*(Number(this.pageSize) - Number(this.datas.length));
		this.content += "<tr><td height='"+trHeight+"px' style='border:0px;'></td></tr>";
	},
	createTdButtonHTML:function(data,column,rowIndex){
		if(column.buttons&&column.buttons.length>0){
			var buttonStr="";
			for(var i=0;i<column.buttons.length;i++){
				var button=column.buttons[i];
				var name=JBF.setObjValue(button.name,button.name,"未定义名称");
				var onclickStr="";
				if(button.fun){
					var funName=column.name+"_"+rowIndex+"_"+i;
					this.pushButtonClickFun({name:funName,fun:this.callButtonClick(rowIndex,data["id"],button.fun)});
					onclickStr="onclick='"+this.tableName+".getTdButtonClick(\""+funName+"\");'";
				}
				buttonStr+="<input type='button' value='"+name+"' "+onclickStr+">&nbsp;";
			}
			return buttonStr;
		}
		return "";
	},
	pushButtonClickFun:function(clickObj){
		var bit=false;
		for(var i=0;i<this.tdButtonEvents.length;i++){
			var bEvent=this.tdButtonEvents[i];
			if(bEvent.name==clickObj.name){
				bit=true;
				break;
			}
		}
		if(!bit){
			this.tdButtonEvents.push(clickObj);
		}
	},
	callButtonClick:function(rowIndex,id,fun){
		return function(){
			if(fun){
				fun(rowIndex,id);
			}
		};
	},
	getTdButtonClick:function(funName){
		alert("funName:"+funName);
		if(this.tdButtonEvents){
			for(var i=0;i<this.tdButtonEvents.length;i++){
				bEvent=this.tdButtonEvents[i];
				if(funName==bEvent.name){
					bEvent.fun();
				}
			}
		}
	},
	createTdInnerHTML:function(column,value){
		if (value != undefined && value != "undefined"
				&& value.length > 0) {
			if (column.type) {// 根据不同的类型进行赋值。
				if(column.type == "option"){
					value= this.fullOption(value, column.value);
				}else{
					value= JBF.getFormatValue(value,column.type);
				}
			}
			if(column.maxLength && value.length > column.maxLength){
				value = value.substr(0, column.maxLength) + "...";
			}
			return value;
		} 
		return "&nbsp;";
	},
	/**
	 * //用于给td增加扩展属性
	 * @param tdColumn
	 * @returns {String}
	 */
	createTdExtra:function(tdColumn){
		var extra = "";
		if (tdColumn.extra) {
			for ( var j = 0; j < tdColumn.extra.length; j++) {
				extra += " " + tdColumn.extra[j][0] + "="
						+ tdColumn.extra[j][1] + " ";
			}
		}
		return extra;
	},
	/**
	 * 用于为可编缉字段增加可编辑控件
	 * @param tdColumn
	 * @param rowIndex
	 * @returns {String}
	 */
	createEditEvent:function(tdColumn,rowIndex){
		if(tdColumn&&tdColumn.isEdit){
			var onDbClickStr=" ondblclick='"+this.tableName+".createEditInput(event,this,\""+tdColumn.name+"\","+rowIndex+")' ";
			return onDbClickStr;
		}
		return "";
	},
	createEditInput:function(ev,tdObj,columnName,rowIndex){
		ev.cancelBubble=true;
		if(!(tdObj.attributes["isEdit"]&&tdObj.attributes["isEdit"].nodeValue=="true")){
			var height=(tdObj.clientHeight-8)+"px";
			var width="98%";
			var tdColumn=this.getColumnByName(columnName);
			if(tdColumn){
				var editName=tdColumn.name+"EditInput_"+rowIndex;
				var type="text";
				if(tdColumn.type){
					type=tdColumn.type;
				}
				if(type=="text"){
					tdObj.innerHTML="<input type='text' id='"+editName+"' onkeydown='JBF.getKeyValue(event)==13?event.keyCode=9:event.keyCode'"
					+" name='"+editName+"' onclick='event.cancelBubble=true;' style='width:"+width+"; height:"+height+";border:1px solid #ff0000;'"
					+" value='"+tdObj.innerText+"'>";
				}else if(type=="option"){
					var selStr="";
					selStr+="<select id='"+editName+"' name='"+editName+"' onclick='event.cancelBubble=true;'";
					selStr+=" style='width:"+width+"; height:"+height+";border:1px solid #ff0000;' >";
					selStr+=function(){
						var sptionStr="";
						if(tdColumn.value){
							for(var i=0;i<tdColumn.value.length;i++){
								var option=tdColumn.value[i];
								sptionStr+="<option value='"+option.value+"'>"+option.showText+"</option>";
							}
							return sptionStr;
						}
						return "";
					}();
					+"</select>";
					tdObj.innerHTML=selStr;
				}
			}
			tdObj.setAttribute("isEdit","true");
		}
	},
	/**
	 * 为新建可编缉下拉框做准备
	 * @param ev
	 * @param tdObj
	 * @param rowIndex
	 * @param editName
	 */
	createEditOption:function(ev,tdObj,rowIndex,editName){
		
	},
	/**
	 * 赋值select类型
	 */
	fullOption : function(value, Options) {
		if (Options) {
			for ( var i = 0; i < Options.length; i++) {
				if (Options[i].value == value) {
					return Options[i].showText;
				}
			}
		}
		return "<font color=#ff0000>错误值 ("+ value+")</font>";
	},
	pageSizeChange : function() {
		this.pageIndex = 1;
	},
	/**
	 * 整合表尾内容
	 */
	createTableFoot : function() {
		this.pageCount = parseInt(this.totalRows / this.pageSize);
		if (this.totalRows % this.pageSize > 0) {
			this.pageCount += 1;
		}
		this.createBasicFooter();
	},
	createBasicFooter : function() {
		var pageBtn = "<ul>";
		if (this.tableStructure.pages) {
			if (typeof (this.tableStructure.pages) == "string") {
				this.tableStructure.pages = JBF
						.strToObj(this.tableStructure.pages);
			}
			var optionStr = "";
			for ( var i = 0; i < this.tableStructure.pages.length; i++) {
				var value = this.tableStructure.pages[i];
				var selectedStr = "";
				if (value == this.pageSize) {
					selectedStr = "selected='selected'";
				}
				optionStr += "<option " + selectedStr + " value='" + value
						+ "'>" + value + "</option>";
			}
			pageBtn += "<li><select onchange='" + this.tableName
					+ ".pageSizeChange()' id='" + this.tableName
					+ "pageSize' name='" + this.tableName + "pageSize'>"
					+ optionStr + "</select></li>";
		}

		if (this.pageIndex && this.pageIndex > 1) {
			pageBtn += "<li><div class='splitDiv'></div></li><li><div class='footerBtnDiv' onmouseover='"
					+ this.tableName
					+ ".btn_over(this);' onclick='"
					+ this.tableName
					+ ".pre_first();' onmouseout='"
					+ this.tableName
					+ ".btn_out(this)'><span class='footerBtn footerIcon_first' title='首页'></span></div></li><li><div class='footerBtnDiv' onmouseover='"
					+ this.tableName
					+ ".btn_over(this)' onclick='"
					+ this.tableName
					+ ".pre_page();' onmouseout='"
					+ this.tableName
					+ ".btn_out(this)'><span class='footerBtn footerIcon_prev' title='上一页'></span></div></li>";
		}
		pageBtn += "<li><div class='splitDiv'></div></li>"
				+ this.createPageBlocks();
		pageBtn += "<li><div class='splitDiv'></div></li><li><font color='red'>"
				+ this.pageIndex + "</font> / " + this.pageCount + "</li>";
		if (this.pageIndex < this.pageCount) {
			pageBtn += "<li><div class='splitDiv'></div></li><li><div class='footerBtnDiv' onmouseover='"
					+ this.tableName
					+ ".btn_over(this)' onclick='"
					+ this.tableName
					+ ".next_page();' onmouseout='"
					+ this.tableName
					+ ".btn_out(this)'><span class='footerBtn footerIcon_next' title='下一页'></span></div></li><li><div class='footerBtnDiv' onmouseover='"
					+ this.tableName
					+ ".btn_over(this)' onclick='"
					+ this.tableName
					+ ".next_end();' onmouseout='"
					+ this.tableName
					+ ".btn_out(this)'><span class='footerBtn footerIcon_last' title='尾页'></span></div> </li>";
		}
		pageBtn += "<li><div class='splitDiv'></div></li><li><input id='"
				+ this.tableName
				+ "FlushInput'  value='' onkeyup='JBF.replaceNum(this);'  class='fonterJumpInput'></li><li><div class='footerBtnDiv' onmouseover='"
				+ this.tableName
				+ ".btn_over(this)' onclick='"
				+ this.tableName
				+ ".flush_page();' onmouseout='"
				+ this.tableName
				+ ".btn_out(this)'><span class='footerBtn footerIcon_brush' title='刷新'></span></div> </li><li><div class='splitDiv'></div></li>";
		var showPageSize = ((this.pageIndex - 1) * this.pageSize + 1) + "-"
				+ ((this.pageIndex - 1) * this.pageSize + this.getRowsCount());
		var buttons = JBF.getCopyButtonsHTML(this.buttonDatas);
		var buttonStr = "<li style='float:right'>当前<font color='red'>" + showPageSize + "</font>,总计<font color='red'> "
				+ this.totalRows + "</font>,每页<font color='red'>" + this.pageSize + "</font></li>&&&";
		if (buttons && buttons.length > 0) {
			pageBtn += buttonStr.replace("right", "left").replace("&&&",
					"<li style='float:right'>" + buttons + "</li>");
		} else {
			pageBtn += buttonStr.replace("&&&", "");
		}
		pageBtn += "</ul>	";
		this.footer = pageBtn;
	},
	createPageBlocks : function() {
		var blockStr = "";
		if (this.pageIndex) {
			var length = 6;
			var minValue = 1;
			var maxValue = this.pageCount;
			var avg = (length % 2 == 0) ? (length / 2) : (length / 2 + 1);
			if (this.pageIndex > avg) {
				if ((this.pageIndex + avg) < this.pageCount) {
					maxValue = this.pageIndex + avg;
				} else {
					maxValue = this.pageCount;
				}
			} else if (this.pageCount < length) {
				maxValue = this.pageCount;
			} else {
				maxValue = length;
			}

			if (maxValue > length) {
				minValue = maxValue - length + 1;
			} else {
				minValue = 1;
			}
			for ( var i = minValue; i <= maxValue; i++) {
				className = 'footerDivSelect';
				if (i == this.pageIndex) {
					className = 'footerDivSelected';
				}
				blockStr += "<li><a onclick='" + this.tableName
						+ ".flush_page(" + i + ")' href='javascript:void(0)' class='"
						+ className + "'>&nbsp;" + i + "&nbsp;</a></li>";
			}
		}
		return blockStr;
	},
	updateRowByIndex : function(index, data) {
		if (this.datas.length > 0) {
			if (index < this.datas.length) {
				this.datas[index] = data;
				this.refreshDatas();
			} else {
				alert("修改数据索引不存在");
			}
		} else {
			alert("表格中没有数据，不能进行修改操作");
		}
	},
	updateRowById : function(id, data) {
		for ( var i = 0; i < this.datas.length; i++) {
			var data = this.datas[i];
			if (data["id"] && data["id"] == id) {
				this.updateRowByIndex(i, data);
				break;
			}
		}
	},
	insertRow : function(index, data) {
		if (index < this.datas.length) {
			this.datas.splice(index, 0, data);
		} else {
			this.datas.push(data);
		}
		this.refreshDatas();
	},
	deleteRowByIndex : function(index) {
		if (this.datas.length > 0) {
			if (index < this.datas.length) {
				this.datas.splice(index, 1);
			} else {
				alert("删除的记录索引不存在");
			}
		} else {
			alert("表格中没有数据，不能进行删除操作");
		}
		this.refreshDatas();
	},
	deleteRowById : function(id) {
		if (this.datas.length > 0) {
			for ( var i = 0; i < this.datas.length; i++) {
				var data = this.datas[i];
				if (data["id"] == id) {
					this.deleteRowByIndex(i);
					break;
				}
			}
		}
	},
	selectRow : function(rowIndex) {
		//alert("rowIndex:"+rowIndex+"  this.datas.length:"+this.datas.length);
		if (rowIndex >= this.datas.length || rowIndex < 0) {
			alert("错误的序号");
			return;
		}
		this.changeRowClassName("trOnClick", rowIndex);
		if(this.isShowCheck){
			if (this.selectType == "radio") {
				JBF.el("radio" + rowIndex).checked = "checked";
			} else if (this.selectType == "check") {
				JBF.el("check" + rowIndex).className = "checkbox_checked";
			}
		}
		if (!this.isRowSelected(rowIndex)) {
			this.selectRowIndexes.push(rowIndex);
		}
	},
	clearDatas:function(){
		this.datas=[];
		this.refreshDatas();
	},
	changeRowClassName : function(className, rowIndex) {
		var table = JBF.el(this.tableId);
		var selectRowIndex = (rowIndex + (table.rows.length - this.datas.length));
		if(this.isShowBlankTr){
			selectRowIndex = (rowIndex + (table.rows.length - this.datas.length-1));
		}
		var tr = table.rows[selectRowIndex];
		if(tr){
			if (className.length > 0) {
				tr.className = className;
				tr.style.backgroundColor = this.trSelectedColor;
			} else {
				if (this.selectType == "check") {
					JBF.el("check" + rowIndex).className = "checkbox";
				}
				if (tr.attributes["srcClass"]) {
					tr.className = tr.attributes["srcClass"].value;
				} else {
					tr.className = "";
				}
				tr.style.backgroundColor = "";
			}
		}
	},
	selectRowById : function(id) {
		if (index < this.datas.length) {
			for ( var i = 0; i < this.datas.length; i++) {
				var data = this.datas[i];
				if (data["id"] == id) {
					selectRow(i);
					break;
				}
			}
		}
	},

	/***************************************************************************
	 * 表格配置块内容
	 **************************************************************************/
	showTableConfig : function(ev) {
		ev.cancelBubble = true;
		if (this.tableConfigDiv) {
			this.tableConfigDiv.style.display = "inline";
			this.tableConfigDiv.innerHTML = "";
		} else {
			this.tableConfigDiv = document.createElement("div");
			this.tableConfigDiv.className = "tableConfigMainDiv";
			this.tableConfigDiv.style.left = JBF.pointerX(ev) + "px";
			this.tableConfigDiv.style.top = JBF.pointerY(ev) + "px";
			JBF.addEvent(this.tableConfigDiv, 'click', function() {
				window.event.cancelBubble = true;
			});
			document.body.appendChild(this.tableConfigDiv);
		}
		var checkStr = "<div class='tableConfigTitle'><a href='javascript:void(0)'   onclick='"
				+ this.tableName + ".tableConfigSelectAll(1)' >全选</a>"
				+ "<a href='javascript:void(0)'   onclick='" + this.tableName
				+ ".tableConfigSelectAll(2)'>还原</a>" + "<a href='javascript:void(0)' onclick='"
				+ this.tableName + ".tableConfigSelectAll(3)'>返选</a>"
				+ "<a href='javascript:void(0)' onclick='" + this.tableName
				+ ".saveTableConfig();'>保存配置</a>" + "<a href='javascript:void(0)' onclick='"
				+ this.tableName + ".clearTableConfig();'>清空配置</a>"
				+ "<a href='javascript:void(0)' style='float:right;' onclick='" + this.tableName
				+ ".closeTableConfig()();'>关闭</a></div>";
		if (this.columns) {
			checkStr += "<div style='float:left;'><table>";
			var colorsStr = "";
			for ( var i = 0; i < this.columnsColors.length; i++) {
				colorsStr += "<option style='background-color:"
						+ this.columnsColors[i] + ";' value='"
						+ this.columnsColors[i]
						+ "'>&nbsp;&nbsp;&nbsp;</option>";
			}
			for ( var i = 0; i < this.columns.length; i++) {
				var column = this.columns[i];
				var checked = "";
				for ( var j = 0; j < this.cookieColumns.length; j++) {
					if (column["name"] == this.cookieColumns[j]["name"]) {
						checked = " checked=checked;";
						break;
					}
				}
				checkStr += "<tr><td><input type='checkbox' "
						+ checked
						+ " name='"
						+ this.tableName
						+ "TableConfigDiv' value='"
						+ column['name']
						+ "'></td><td>"
						+ column['display']
						+ "</td>"
						+ "<td>宽：<input type='text' onkeyup=JBF.replaceNum(this) style='width:30px;'  name='"
						+ this.tableName + "TableConfigWidth' value='"
						+ column['width'] + "'>px</td>" + "<td>颜色：<select>"
						+ colorsStr + "</select></td>";
			}
			;
		}
		if (checkStr.length > 0) {
			checkStr += "</table></div><div><table><tr>"
					+ "<td>表头颜色:</td><td><input class='tableConfigTitleColor' id='"
					+ this.tableName
					+ "TableTitleColor' onclick='JBF.showColorPanel();'></td> "
					// +"<td>字体颜色:</td><td><input class='tableConfigTitleColor'
					// id='"+this.tableName+"FontTitleColor'
					// onclick='JBF.showColorPanel();'></td> </tr>"
					+ "<tr><td>奇数行颜色:</td><td><input class='tableConfigTitleColor' id='"
					+ this.tableName
					+ "OddTrColor'  onclick='JBF.showColorPanel();'></td>"
					+ "<td>偶数行颜色:</td><td><input class='tableConfigTitleColor' id='"
					+ this.tableName
					+ "EvenTrColor"
					+ "' onclick='JBF.showColorPanel();'></td></tr>"
					+ "<tr><td>经过颜色:</td><td><input class='tableConfigTitleColor' style='background-color:"
					+ this.trOverColor
					+ "' id='"
					+ this.tableName
					+ "MouseOverColor' value='"
					+ this.trOverColor
					+ "' onclick='JBF.showColorPanel();'></td>"
					+ "<td>选中颜色:</td><td><input class='tableConfigTitleColor' style='background-color:"
					+ this.trSelectedColor
					+ "' id='"
					+ this.tableName
					+ "MouseSelectedColor' value='"
					+ this.trSelectedColor
					+ "' onclick='JBF.showColorPanel();'></td></tr></table></div>";
		}
		this.tableConfigDiv.innerHTML = checkStr;
		JBF.addEvent(document.body, "click", this.closeTableConfig());
	},
	tableConfigSelectAll : function(checkType) {
		var configCheck = JBF.elByName(this.tableName + "TableConfigDiv");
		for ( var i = 0; i < configCheck.length; i++) {
			var check = configCheck[i];
			if (checkType == '1') {
				if (!check.checked) {
					check.checked = 'true';
				}
			} else if (checkType == "2") {
				if (check.checked) {
					check.checked = '';
				}
			} else if (checkType == '3') {
				if (check.checked) {
					check.checked = '';
				} else {
					check.checked = 'true';
				}
			}
		}
	},
	saveTableConfig : function() {
		var checkStr = "columns:[";
		var overColor = JBF.el(this.tableName + "MouseOverColor").value;// 鼠标经过颜色
		var selectedColor = JBF.el(this.tableName + "MouseSelectedColor").value;// 行选中颜色
		var oddTrColor = JBF.el(this.tableName + "OddTrColor").value;// 奇数行颜色
		var evenTrColor = JBF.el(this.tableName + "EvenTrColor").value;// 偶数行颜色
		var tableTitleColor = JBF.el(this.tableName + "TableTitleColor").value; // 表头颜色
		var tableFontColor = JBF.el(this.tableName + "TableTitleColor").value;// 文字颜色
		var colorStr = "colors:{overColor:'" + overColor + "',selectedColor:'"
				+ selectedColor + "',oddTrColor:'" + oddTrColor
				+ "',evenTrColor:'" + evenTrColor + "',tableTitleColor:'"
				+ tableTitleColor + "',tableFontColor:'" + tableFontColor
				+ "'}";
		var configCheck = JBF.elByName(this.tableName + "TableConfigDiv");
		var widths = JBF.elByName(this.tableName + "TableConfigWidth");
		for ( var i = 0; i < configCheck.length; i++) {
			var check = configCheck[i];
			if (check.checked) {
				checkStr += "{name:'" + check.value + "',width:'"
						+ widths[i].value + "'},";
			}
		}
		if (checkStr.length > 0) {
			checkStr = checkStr.substring(0, checkStr.length - 1) + "]";
		}
		var saveStr = "{" + checkStr + "," + colorStr + "}";
		// 保存表格配置信息到本地cookie
		JBF.saveCookie("columns", 1000, saveStr);
		this.closeTableConfig()();
	},
	clearTableConfig : function() {
		JBF.saveCookie("columns", -10, "");
	},
	/**
	 * 关闭表格配置信息
	 * 
	 * @returns
	 */
	closeTableConfig : function() {
		var op = this;
		this.closeMethod = function() {
			op.tableConfigDiv.style.display = 'none';
			JBF.removeEvent(document.body, 'click', op.closeMethod);
			JBF.closeColorPanel();
		};
		return this.closeMethod;
	},
	/***************************************************************************
	 * 封装死的增加
	 **************************************************************************/
	add : function(width, height) {
		var url = this.opCode + 'Add.html';
		var returnValue = window.showModalDialog(url, window, this.openWinStyle);
		//window.open(url);
		if (returnValue) {
			this.addPojo(returnValue);
		}
		// window.open(url);
	},
	openByUrl : function(url, width, height) {
		var defaultStyle="";
		if(width&&height){
			defaultStyle= "dialogWidth=" + width + "px;dialogHeight=" + height+ "px";
		}else{
			defaultStyle=this.openWinStyle;
		}
		window.showModalDialog(url, window, defaultStyle);
	},
	modify : function(width, height) {
		if (this.selectRowIndexes.length == 0
				|| this.selectRowIndexes.length > 1) {
			alert("请选择一条记录后再进行修改操作");
			return ;
		}
		var url = this.opCode + 'Modify.html?id=' + this.getSelectedValues();
		var returnValue = window.showModalDialog(url, window, this.openWinStyle);
		if (returnValue) {
			this.modifyPojo(returnValue);
		}
	},
	view : function(width, height) {
		if (this.selectRowIndexes && this.selectRowIndexes.length > 0) {
			var id = this.getSelectedValues("id");
			var code = this.getSelectedValues("code");
			var name = this.getSelectedValues("name");
			if (id) {
				var url = (this.opCode + '.html?id=' + id + "&code=" + code + "&name=" + name);
				window.open(url);
			} else {
				alert("请选择一条记录");
			}
		} else {
			alert('请选择一条记录');
		}
	},
	getPageIndex:function(){
		return this.pageIndex;
	},
	getPageSize:function(){
		return this.pageSize;
	},
	getSelectIndex:function(){
		return this.keyIndexs;
	},
	del : function() {
		var delUrl = this.url.replace('query', 'delete');
		this.delPojo(delUrl);
	},
	query : function() {
		this.pageIndex = 1;
		this.searchByForm();
	},
	toExcel : function() {
		searchBit=true;
		var params=this.getParams();
		if(this.checkedForm&&params.length<=0){
			searchBit=false;
		} 
		if(searchBit){
			var linkChar="?";
			if(this.url.indexOf("?")>-1){
				linkChar="&";
			}
			var url = this.url.replace('query', 'queryForExcel') + linkChar +params;
			window.location.href = url;
		}
	},
	toTreeMode : function() {
		window.location.href = this.opCode + "ManageTree.html";
	},
	toListMode : function() {
		window.location.href = this.opCode + "Manage.html";
	}
};

/** 工具栏及查询块* */
var defaultTableButtons = {
	datas : [ {
		showName : '查询',
		icon : 'search',
		method : "table.query()"

	}, {
		showName : '增 加',
		icon : 'add',
		method : "table.add(1200,500)",
		copy : true

	}, {
		showName : '删 除',
		icon : 'delete',
		method : "table.del()",
		copy : true
	}, {
		showName : '修 改',
		icon : 'modify',
		method : "table.modify(1200,500)",
		copy : true

	}, {
		showName : '详细信息',
		icon : 'detail',
		method : "table.view(1200,500)",
		copy : true

	}, {
		showName : 'Excel',
		icon : 'detail',
		method : "table.toExcel()",
		copy : true

	} ]
};


/*******************************************************************************
 * 颜色面板块
 * 
 * @param colorObj
 * @param opObj
 * @returns
 */
function ColorPanel(colorObj, opObj) {
	this.keyStatus = false;
	this.startX = 0;
	this.maxLength = 128;
	this.rColor = 0;
	this.gColor = 0;
	this.bColor = 0;
	this.bit = "1";
	this.moveObj = null;
	this.colorObj = colorObj;
	this.objLeft = 0;
	this.color = "#000000";
	this.opObj = opObj;
}
ColorPanel.prototype = {
	constructor : ColorPanel,
	getX : function(ev) {

		return ev.screenX;

	},
	getEventTarget : function(ev) {
		if (ev.srcElement) {
			return ev.srcElement;
		} else {
			return ev.target;
		}
	},
	mouseDown : function(status) {
		this.keyStatus = true;
		var ev = window.event;
		this.moveObj = this.getEventTarget(ev);
		this.objLeft = Number(this.moveObj.style.left.replace("px", ""));
		this.startX = this.getX(ev);
		this.bit = status + "";
		window.event.cancelBubble = true;
	},
	mouseMove : function() {
		if (this.keyStatus) {
			var ev = window.event;
			var moveX = this.getX(ev) - this.startX;
			var colorValue = (this.objLeft + moveX);
			if (colorValue > this.maxLength) {
				colorValue = this.maxLength;
			} else if (colorValue < 0) {
				colorValue = 0;
			}
			this.moveObj.style.left = colorValue + "px";
			var dbColor = colorValue * 2;
			if (dbColor > 255) {
				dbColor = 255;
			}
			if (this.bit == "1") {
				this.rColor = dbColor;
			} else if (this.bit == "2") {
				this.gColor = dbColor;
			} else if (this.bit == "3") {
				this.bColor = dbColor;
			}
			this.getColor();
		}
		window.event.cancelBubble = true;
	},
	getColor : function() {
		this.color = "#" + JBF.to16(this.rColor) + JBF.to16(this.gColor)
				+ JBF.to16(this.bColor);
		JBF.el(this.colorObj + "MinColor").style.backgroundColor = this.color;
		JBF.el(this.colorObj + "InputColor").value = this.color;
		this.opObj.value = this.color;
		this.opObj.style.backgroundColor = this.color;
	},
	mouseUp : function() {
		this.keyStatus = false;
		window.event.cancelBubble = true;
	},
	show : function(colorStr) {
		var colorLeftStyle = "";
		if (colorStr) {
			colorStr = colorStr.replace("#", "");
		} else {
			colorStr = "000000";
		}
		var str = "<div class='colorPanel' onclick='window.event.cancelBubble=true;' onmousemove='"
				+ this.colorObj
				+ ".mouseMove();' onmouseup='"
				+ this.colorObj
				+ ".mouseUp()'>";
		str += "<div id='"
				+ this.colorObj
				+ "MinColor' style='width:16px;height:16px; float:left;margin-right:10px;background-color:#"
				+ colorStr
				+ ";border:1px solid #880000;'></div><div style='float:left;'><input style='width:80px;border:none;' id='"
				+ this.colorObj + "InputColor'></div>";
		for ( var i = 1; i < 4; i++) {
			var otherClass = "blue";
			colorLeftStyle = colorStr.substring((i - 1) * 2, i * 2);
			colorLeftStyle = parseInt("0x" + colorLeftStyle, 16);
			switch (i) {
			case 1:
				this.rColor = colorLeftStyle;
				otherClass = "red";
				break;
			case 2:
				this.gColor = colorLeftStyle;
				otherClass = "green";
				break;
			case 3:
				this.bColor = colorLeftStyle;
				otherClass = "blue";
				break;
			}
			colorLeftStyle = "style='left:" + colorLeftStyle / 2 + "px;'";
			str += "<div class='parentDiv " + otherClass
					+ "'><div class='childDiv' " + colorLeftStyle
					+ " onmouseout='event.cancelBubble=true;' onmousedown='"
					+ this.colorObj + ".mouseDown(" + i + ");'></div></div>";
		}
		return str + "</div>";
	}
};
